package com.hxci.hospital.service.impl;

import com.hxci.hospital.dao.PatientMapper;
import com.hxci.hospital.pojo.Patient;
import com.hxci.hospital.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PatientServiceImpl implements PatientService {

    @Autowired
    private PatientMapper patientMapper;

    @Override
    public int add(Patient patient) {
        // 设置创建时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        patient.setCreateTime(sdf.format(new Date()));
        // 初始状态为待就诊
        patient.setStatus(0);
        return patientMapper.add(patient);
    }

    @Override
    public Patient queryById(Integer id) {
        return patientMapper.queryById(id);
    }

    @Override
    public List<Patient> queryAll() {
        return patientMapper.queryAll();
    }

    @Override
    public List<Patient> queryByDoctorId(Integer doctorId) {
        return patientMapper.queryByDoctorId(doctorId);
    }
    
    @Override
    public List<Patient> queryByDepartment(String department) {
        return patientMapper.queryByDepartment(department);
    }

    @Override
    public int update(Patient patient) {
        return patientMapper.update(patient);
    }

    @Override
    public int updateStatus(Integer id, Integer status) {
        return patientMapper.updateStatus(id, status);
    }
}
